<!DOCTYPE html>
<html lang='zh-CN'>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
  <title>城市管理</title>
  <link rel="icon" href="favicon.ico" type="image/ico">
  <link href="css/bootstrap.min.css" rel="stylesheet">
  <link href="css/materialdesignicons.min.css" rel="stylesheet">
  <link href="css/animate.css" rel="stylesheet">
  <link href="css/style.min.css" rel="stylesheet">
  <link href="js/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
  <link rel="stylesheet" href="js/ztree/zTreeStyle/zTreeStyle.css" type="text/css">
  <link rel="stylesheet" href="js/dropzone/min/basic.min.css" />
  <link rel="stylesheet" href="js/dropzone/min/dropzone.min.css" />
  <link rel="stylesheet" type="text/css" href="js/webuploader/webuploader.css">
  <link rel="stylesheet" type="text/css" href="js/magnific-popup/magnific-popup.min.css">
</head>
<body>
<div class="container-fluid">


  <div class="row">
    <div class="col-md-3">
      <div class="card">
        <div class="card-header">
          <h4>城市管理</h4>
          <div>
            <button class="btn btn-info btn-xs btn-round" id="editBtn">编辑</button>
          </div>
        </div>
        <div class="card-body">

          <div class="zTreeDemoBackground left">
            <ul id="tree" class="ztree"></ul>
          </div>

        </div>
      </div>
    </div>
    <div class="col-md-9">
      <div class="card">
        <div class="card-header">
          <h4>城市详情</h4>
        </div>
        <div class="card-body">
          <form id="searchForm">
            <input id="ids" name="ids" type="hidden" value="">
          </form>
          <table id="tb_city"></table>

        </div>
      </div>
    </div>

  </div>

  <!--  添加与编辑模态框 -->
  <div class="modal fade" id="addOrEditModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title" id="exampleModalLabel">城市详情管理</h4>
        </div>
        <div class="modal-body">
          <form id="addOrEditForm" method="post" >
            <input type="hidden" id="areaId" name="areaId">
            <div class="start">
              <button class="btn btn-success btn_query btn-round" type="button" id="addBtn" >添加图片</button>
            </div>
          <div class="form-group col-md-6">
            <div class="row">
                  <div class="js-upload-logo">
                    <label for="picker_logo" class="control-label">logo：</label>
                    <input type="hidden" name="logo"  id="logo" value="">
                    <div id="picker_logo">上传logo</div>
                    <ul id="file_list_logo" class="list-inline clearfix lyear-uploads-pic">
                    </ul>
                  </div>
            </div>
           </div>
           <div class="form-group col-md-6" >
            <div class="row">
                <div class="js-upload-photo">
                  <label for="picker_photo" class="control-label">背景图：</label>
                    <input type="hidden" name="photo"  id="photo" value="">
                    <div id="picker_photo">上传背景图</div>
                    <ul id="file_list_photo" class="list-inline clearfix lyear-uploads-pic"></ul>
              </div>
            </div>
           </div>
            <div class="row">
              <div class="col-xs-12">
                <div class="input-group m-b-10">
                  <label for="editor" class="control-label">城市内容：</label>
                  <textarea id="editor" name="details"></textarea>
                </div>
              </div>
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
              <button type="button" id="subtn" class="btn btn-primary">保存</button>
            </div>
          </form>
    </div>
      </div>
    </div>
  </div>

</div>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/bootstrap-table/bootstrap-table.js"></script>
<script type="text/javascript" src="js/bootstrap-table/bootstrap-table-zh-CN.min.js"></script>
<script type="text/javascript" src="js/zero2one/zero2one.version.js"></script>
<script type="text/javascript" src="js/zero2one/zero2one.core.js"></script>
<!-- bootstrap表单验证插件 -->
<script type="text/javascript" src="js/bootstrap-validator-master/dist/validator.js"></script>
<!-- jquery-form表单提交插件 -->
<script type="text/javascript" src="js/jquery-form/jquery.form.js"></script>
<!-- bootstrap弹出框插件 -->
<script type="text/javascript" src="js/jquery.bootstrap.min.js"></script>
<!-- 表单填充插件 -->
<script type="text/javascript" src="js/jquery-form/jquery.formloader.js"></script>
<!-- ztree树插件 -->
<script type="text/javascript" src="js/ztree/jquery.ztree.core.min.js"></script>
<script type="text/javascript" src="js/zero2one/zero2one.ztree.js"></script>
<!-- ckeditor富文本插件 -->
<script src="js/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="js/bootstrapvalidator/dist/js/bootstrapValidator.js"></script>
<script type="text/javascript" src="js/dropzone/min/dropzone.min.js"></script>
<!--上传图片插件-->
<script type="text/javascript" src="js/webuploader/webuploader.min.js"></script>
<script type="text/javascript" src="js/magnific-popup/jquery.magnific-popup.min.js"></script>
<script type="text/javascript" src="js/zero2one/zero2one.uploader.js"></script>
<script type="text/javascript" src="js/inputmoney.js"></script>

<script type="text/javascript">

  //页面初始化完成加载部门数据
  $.post("/remote/culture/cities", {},
          function(data){
            $.fn.zTree.init($("#tree"), {callback: {onClick: onClick}}, data);
          }, "json");

  var flag;//判断是否是顶级部门
  var zj;
  var tb;
  var ids;
  function onClick(event, treeId, treeNode) {
    flag = treeNode.deptLevel;

    if(treeNode.getParentNode() != null){
      tb = {parentId:treeNode.getParentNode().id, parentName:treeNode.getParentNode().name, id:treeNode.id, name:treeNode.name, deptLevel:treeNode.deptLevel, open:treeNode.open==false?0:1};
    }
    zj = {id:treeNode.id, name:treeNode.name, deptLevel:treeNode.deptLevel, open:treeNode.open};

    if(treeNode.deptLevel == 0){
      getDeptUserByIds();
    }else{
      ids = zero2one.getChildNodes("tree", treeNode);
      $("#ids").val(ids);
      getDeptUserByIds();
    }
  }

  function getDeptUserByIds() {
    //设置表头
    var columns = [
      {checkbox: true},
      {field: 'id',title: 'ID'},
      {field: 'area_name',title: '城市名字'},
      {field: 'logo',title: '城市logo',formatter: function (value, row, index) {
        if (value==null||value==''){
          return '无'
        }else {
          var html = "<img style='width: 80px' src='"+value+"'/>";
          return html;
        }
        }},
      {field: 'logo',title: 'logo',visible:false},
      {field: 'photo',title: '城市背景图',formatter: function (value, row, index) {
          if (value==null||value==''){
            return '无'
          }else {
            var html = "<img style='width: 80px' src='"+value+"'/>";
            return html;
          }
        }},
      {field: 'photo',title: '背景',visible:false},
      {field: 'details',title: '城市详情'}
    ];

    //进入主界面加载数据
    zero2one.datagrid("tb_city", "/remote/culture/queryCity",function (params) {
      return $.extend(zero2one.tableInitParam(params), zero2one.form2json("searchForm"));
    }, columns);


    $('#tb_city').bootstrapTable('refresh');
  }

  //点击添加按钮弹出模态框
  $("#editBtn").click(function () {

    //获取选中行的数据
    var datas = $('#tb_city').bootstrapTable('getSelections');
    //	判断是否选中当前要编辑的部门
    if(tb == null){
      $.messager.alert("温馨提示", "请先选择要编辑的城市再操作");
      return;
    }
    //判断是否是顶级部门
    if(flag == 0){
      $.messager.alert("温馨提示", "省级无需编辑操作");
      return;
    }
    //上传图片
    $(".start").show();
    $(".js-upload-logo").hide();
    $(".js-upload-photo").hide();
    $("#file_list_photo").empty();
    $("#file_list_logo").empty();
    //加载表单数据
    $("#areaId").val(datas[0].id);
    $("#logo").val(datas[0].logo);
    $("#photo").val(datas[0].photo);
    $("#addOrEditModal").modal("show");
    ck.setData(datas[0].details);//ck回显
  });

  //保存按钮的点击事件
  $("#subtn").click(function () {
    //添加与编辑的富文本编辑器
    var data1 = CKEDITOR.instances.editor.getData();
    $("#editor").val(data1);
    zero2one.request("/remote/culture/updateCity",$("#addOrEditForm").serialize(),function (data) {
      if (data.success) {
        window.location.reload();
      }else {
        $.messager.alert("温馨提示", data.msg)
      }
    });
  });

  var ck = CKEDITOR.replace( 'editor' );

  var a= 0;
  $(".start").click(function () {
    $("#picker_photo").show();
    $("#picker_logo").show();
    $(".js-upload-logo").show();
    $(".js-upload-photo").show();
    if (a==0){
      zero2one.webUploader("js-upload-logo",false,"logo");
      zero2one.webUploader("js-upload-photo",false,"photo");
      a++
    }
    $(".start").hide()
  })


</script>

</body>
</html>
